package com.examination.controller.utils;

import javax.servlet.*;
import java.io.IOException;

/**
 * @Auther: GongXl
 * @Date: 022 16:15
 * @Description:
 */
public class SiteHitCounter implements Filter {
    private int hitCount;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // 重置点击计数器
        hitCount = 0;
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {

        // 把计数器的值增加 1
        hitCount++;

        // 输出计数器
        System.out.println("网站访问统计："+ hitCount );

        // 把请求传回到过滤器链
        filterChain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}